package com.estronger.shopmanage.ui.order.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.estronger.shopmanage.R;
import com.estronger.shopmanage.base.BaseActivity;
import com.estronger.shopmanage.ui.order.until.ActivityCollector;
import com.estronger.shopmanage.ui.order.until.Tools;
import com.estronger.shopmanage.ui.order.bean.OrderAttributeBean;
import com.estronger.shopmanage.ui.order.bean.TaocanBean;
import com.estronger.shopmanage.utils.PrefUtils;
import com.estronger.shopmanage.view.AbnormalDeclareView;

import java.util.ArrayList;

public class SelectActionActivity extends BaseActivity implements View.OnClickListener {

    private View rl_root;
    private Activity mContext;
    private TextView tvtitle;
    private ImageView imclose;
    private ListView ltpepole;
    private ArrayList<OrderAttributeBean> attList;
    private String checkedId;
    private int whichBundle;
    ArrayList<TaocanBean> tcAttList;

    @Override
    protected void init() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        rl_root = View.inflate(SelectActionActivity.this,
                R.layout.activity_select_people, null);
        setContentView(rl_root);
        mContext = SelectActionActivity.this;
        setFinishOnTouchOutside(false);
        try {
            if(OrderEntryActivity.TaocMap != null && OrderEntryActivity.TaocMap.size()>0){
                whichBundle = 5;
                tcAttList = OrderEntryActivity.TaocMap.get(5);
                OrderEntryActivity.TaocMap.clear();
            }else{
                Bundle bundle = getIntent().getExtras();
                attList = bundle.getParcelableArrayList(PrefUtils.BUNDLEARRAY);
                whichBundle = bundle.getInt("BUNDLEWHICHMOUDLE",0);
                checkedId = bundle.getString("CHECKEDID", "");
            }
        }catch (Exception e){}

        //设置Theme.Dialog View高度
        WindowManager m = getWindowManager();
        Display d = m.getDefaultDisplay(); // 为获取屏幕宽、高
        WindowManager.LayoutParams p = getWindow().getAttributes();
        p.height = (int) (d.getHeight() * 0.46);
        p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.7
        getWindow().setAttributes(p);
    }

    @Override
    protected void initView() {
        tvtitle = (TextView) findViewById(R.id.tvtitle);
        imclose = (ImageView) findViewById(R.id.imclose);
        ltpepole = (ListView) findViewById(R.id.ltpepole);
    }

    @Override
    protected void initAction() {
        imclose.setOnClickListener(this);
        switch (whichBundle){
            case 3:
                tvtitle.setText("年龄选择");
                Tools.showActionPopList(mContext, attList, checkedId, ltpepole,"SELECT_AGE",true);
                break;
            case 4:
                tvtitle.setText("活动选择");
                Tools.showActionPopList(mContext,attList, checkedId, ltpepole,"SELECT_ACTION",false);
                break;
            case 5:
                tvtitle.setText("套餐类型");
                Tools.showPopList_Tc(mContext,tcAttList,ltpepole);
                break;
            case 6:
                tvtitle.setText("收款类型");
                Tools.showActionPopList(mContext,attList, checkedId, ltpepole,"SELECT_GATHERINGTYPE",false);
                break;
            case 7:
                tvtitle.setText("异常申报类型");
                Tools.showActionPopList(mContext,attList, checkedId, ltpepole, AbnormalDeclareView.BIND_DATA,true);
                break;
            case 8:
                tvtitle.setText("选择图片上传日期");
                Tools.showActionPopList(mContext,attList, checkedId, ltpepole, AbnormalDeclareView.BIND_DATA,true);
                break;
        }
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imclose:
                finish();
                break;
        }
    }
    //跳转界面
    public static void openActivity(Activity activity, int type, ArrayList<OrderAttributeBean> beans, String checkedId, int requestCode) {
        if (SelectActionActivity.class != null && ActivityCollector.isActivityExist(SelectActionActivity.class)) {
            return;
        }
        Bundle bundle4 = new Bundle();
        bundle4.putParcelableArrayList(PrefUtils.BUNDLEARRAY, beans);
        bundle4.putInt("BUNDLEWHICHMOUDLE", type);
        bundle4.putString("CHECKEDID", checkedId);
        Intent intent = new Intent(activity, SelectActionActivity.class);
        intent.putExtras(bundle4);
        activity.startActivityForResult(intent, requestCode);
    }
    public static void openActivity(Activity activity, ArrayList<TaocanBean> tcData) {
        if (SelectActionActivity.class != null && ActivityCollector.isActivityExist(SelectActionActivity.class)) {
            return;
        }
        OrderEntryActivity.TaocMap.put(5, tcData);
        Bundle bundle4 = new Bundle();
        bundle4.putInt("BUNDLEWHICHMOUDLE", 5);
        Intent intent = new Intent(activity, SelectActionActivity.class);
        intent.putExtras(bundle4);
        activity.startActivityForResult(intent, Tools.REQUEST_CODE_CHOISE_MEALTYPE);
    }

}
